﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using System.IO;

public partial class admin_addUser : System.Web.UI.Page
{
    db_users user = new db_users();
    protected void Page_Load(object sender, EventArgs e)
    {
        Server.Execute("../inc/checkPurview.aspx");  // 此处用户权限验证

        if (!IsPostBack)
        {

            tb_id.Text = user.getNewUserId();
        }
    }
    protected void btn_ok_Click(object sender, EventArgs e)
    {
        if (Session["adminName"] == null)
        {
            Response.Write("<script language=javascript>alert('没有权限！');</script>");
            return;
        }
        //string userId = tb_id.Text;
        string userName = tb_name.Text;
        string userEmail = tb_email.Text;
        string userSex;
        if (rbtn_man.Checked)
        {
            userSex = "男";
        }
        else {
            userSex = "女";
        }
        string pwd = "888888";
        if (user.isExistName(userName))
        {
            Response.Write("<script language=javascript>alert('用户名已经存在！')</script>");
        }
        else
        {
            if (user.addUser(userName, pwd, "100", userEmail, userSex, "0"))
            {
                res();
                Response.Write("<script language=javascript>alert('用户添加成功！');</script>");
            }
            else
            {
                Response.Write("<script language=javascript>alert('失败！')</script>");
            }
        }
       
    }
    protected void btn_res_Click(object sender, EventArgs e)
    {
        res();
    }

    private void res()
    {
        tb_name.Text = "";
        tb_email.Text = "";
        rbtn_man.Checked = true;
        rbtn_woman.Checked = false;
        tb_id.Text = user.getNewUserId();
    } 
}